

load('summary_data/figA9.rda')

source('utils.R')

inc1 = ggplot(income_out, aes(pctile, value * 100, color = variable, group = variable)) +
  geom_point() + geom_line() +
  theme_light() +
  facet_wrap( ~ measure, scales = 'free_y') +
  scale_x_continuous(breaks = seq(0, 100, 25)) +
  theme(
    strip.background = element_rect(fill = 'white'),
    strip.text = element_text(color = 'black', face = 'bold')
  ) +
  scale_color_manual(
    values = c(
      'blue',
      'deepskyblue',
      'darkslateblue',
      'chocolate1',
      'brown1',
      'darkred'
    ),
    breaks = c('d2012', 'd2016', 'd2020', 'r2012', 'r2016', 'r2020'),
    labels = toupper(c('d12', 'd16', 'd20', 'r12', 'r16', 'r20'))
  ) +
  labs(x = 'Measure Rank', y = '% of Bin Contributing', color = '') +
  coord_cartesian(xlim = c(0, 100))

nw1 = ggplot(wealth_out, aes(pctile, value * 100, color = variable, group = variable)) +
  geom_point() + geom_line() +
  theme_light() +
  facet_wrap( ~ measure, scales = 'free_y') +
  theme(
    strip.background = element_rect(fill = 'white'),
    strip.text = element_text(color = 'black', face = 'bold')
  ) +
  scale_color_manual(
    values = c(
      'blue',
      'deepskyblue',
      'darkslateblue',
      'chocolate1',
      'brown1',
      'darkred'
    ),
    breaks = c('d2012', 'd2016', 'd2020', 'r2012', 'r2016', 'r2020'),
    labels = toupper(c('d12', 'd16', 'd20', 'r12', 'r16', 'r20'))
  ) +
  labs(x = 'Measure Rank', y = '% of Bin Contributing', color = '') +
  scale_x_continuous(breaks = seq(0, 100, 25), labels = seq(0, 100, 25)) +
  coord_cartesian(xlim = c(0, 100))

tmp = plot_grid(
  inc1 + theme(legend.position = 'none') + labs(subtitle = '(A) Income vs. NWR'),
  nw1  + theme(legend.position = 'none') + labs(subtitle = '(B) Net Worth vs. NWR')
)

pl = plot_grid(
  tmp,
  get_legend_35(
    nw1 +
      theme(legend.position = 'bottom') +
      guides(color = guide_legend(nrow = 1, title = '        Campaign'))
  ),
  nrow = 2,
  rel_heights = c(0.9, .05)
)

ggsave(filename = 'figures/figA9.pdf', plot = pl, width = 10, height = 5)
